var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
    })(t, e);
}, function(t, e) {
    function n() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (n.prototype = e.prototype, 
    new n());
}), a = this && this.__decorate || function(t, e, o, n) {
    var i, s = arguments.length, c = s < 3 ? e : null === n ? n = Object.getOwnPropertyDescriptor(e, o) : n;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) c = Reflect.decorate(t, e, o, n); else for (var h = t.length - 1; 0 <= h; h--) (i = t[h]) && (c = (s < 3 ? i(c) : 3 < s ? i(e, o, c) : i(e, o)) || c);
    return 3 < s && c && Object.defineProperty(e, o, c), c;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("GameData"), s = e("AudioManager"), c = e("DataManager"), l = e("EggsManager"), d = e("LoadManager"), u = e("UIManager"), p = e("WebManager"), h = e("Global"), f = e("PersonView"), g = cc._decorator, m = g.ccclass, y = g.property, v = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.target = null, t.btnNode = null, t.personView = null, t.touchArea = null, 
        t.touchId = null, t.isCheck = !1, t.isCheck2 = !1, t.count = 0, t.total = 10, t.idx = 15, 
        t.pos = cc.v2(), t.originPos = cc.v2(), t;
    }
    return i(t, e), t.prototype.onEnable = function() {
        -1 == l.default.getInstance().checkEggPerson(this.idx) && this.addTouchEvent();
    }, t.prototype.onDisable = function() {
        this.removeTouchEvent();
    }, t.prototype.onDestroy = function() {
        cc.systemEvent.off("refresh_person_skin", this.doRefresh, this);
    }, t.prototype.onClick = function() {
        var t = this;
        -1 == l.default.getInstance().checkEggPerson(this.idx) && (p.default.getInstance().sentLog("获得皮肤彩蛋id:" + this.idx), 
        s.default.getInstance().playAudio("皮肤出现"), u.default.getInstance().loadPopPnl("egg_reward", {
            type: h.RewardType.SKIN,
            idx: this.idx
        }, function() {
            t.target.setPosition(t.pos);
        }), this.removeTouchEvent(), l.default.getInstance().updateEggPerson(this.idx), 
        r.GD.personIdx = -1 - this.idx, r.GD.eggsHintState = 1, c.default.getInstance().save(), 
        cc.systemEvent.off("refresh_person_skin", this.doRefresh, this));
    }, t.prototype.start = function() {
        this.pos = this.target.getPosition();
    }, t.prototype.init = function() {
        this.originPos = this.target.getPosition(), this.btnNode = new cc.Node(), d.default.getInstance().loadSpriteFrame({
            url: "image/eggs/灰大狼@2x",
            sprite: this.btnNode.addComponent(cc.Sprite)
        }), this.btnNode.zIndex = -1, this.btnNode.setPosition(this.originPos), this.btnNode.parent = this.target.parent, 
        this.doRefresh(), cc.systemEvent.on("refresh_person_skin", this.doRefresh, this);
    }, t.prototype.doRefresh = function() {
        var t;
        this.target.setPosition(this.originPos), this.btnNode.setPosition(this.originPos), 
        this.count < this.total && this.count++, this.count == this.total && this.personView && 11 == this.personView.personIdx && r.GD.hasSkin(11) && -1 == l.default.getInstance().checkEggPerson(this.idx) ? (this.node.active = !0, 
        (t = this.target.getComponent(cc.Button)) && 0 == t.interactable ? (this.touchArea.active = !0, 
        this.btnNode.active = !0) : (this.touchArea.active = !1, this.btnNode.active = !1)) : (this.node.active = !1, 
        this.btnNode.active = !1);
    }, t.prototype.addTouchEvent = function() {
        this.touchArea.on(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), 
        this.touchArea.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this), this.touchArea.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), 
        this.touchArea.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this);
    }, t.prototype.removeTouchEvent = function() {
        this.touchArea.off(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), 
        this.touchArea.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this), this.touchArea.off(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), 
        this.touchArea.off(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this);
    }, t.prototype.touchStartHandler = function(t) {
        var e;
        null == this.touchId && (this.touchId = t.getID()), this.touchId == t.getID() && (e = t.getLocation(), 
        t = this.target.convertToNodeSpaceAR(e), Math.abs(t.x) <= this.target.width / 2 && Math.abs(t.y) <= this.target.height / 2 ? this.isCheck = !0 : (e = this.btnNode.convertToNodeSpaceAR(e), 
        Math.abs(e.x) <= this.btnNode.width / 2 && Math.abs(e.y) <= this.btnNode.height / 2 && (this.isCheck2 = !0)));
    }, t.prototype.touchMoveHandler = function(t) {
        this.touchId == t.getID() && (this.isCheck ? this.target.setPosition(this.target.parent.convertToNodeSpaceAR(t.getLocation())) : this.isCheck2 && this.btnNode.setPosition(this.btnNode.parent.convertToNodeSpaceAR(t.getLocation())));
    }, t.prototype.touchEndHandler = function(t) {
        var e, o;
        this.touchId = null, this.isCheck && (this.isCheck = !1), this.isCheck2 && (this.isCheck2 = !1, 
        e = this.btnNode.convertToWorldSpaceAR(cc.Vec2.ZERO), o = this.personView.node.convertToWorldSpaceAR(cc.Vec2.ZERO), 
        100 <= e.y - o.y && e.y - o.y <= 200 && Math.abs(e.x - o.x) < 100 && (cc.tween(this.btnNode).to(.1, {
            scale: 1.1
        }).to(.1, {
            scale: 1
        }).start(), this.onClick(t)));
    }, a([ y(cc.Node) ], t.prototype, "target", void 0), a([ y(f.default) ], t.prototype, "personView", void 0), 
    a([ y(cc.Node) ], t.prototype, "touchArea", void 0), a([ m ], t);
}(cc.Component);

n.default = v;